home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / imengv3.41p2.lha / ImEngV3.41p2 / Extra / MainActor / IE_BatchProcess.ma next >
Text File  |  1996-10-14  |  13KB  |  430 lines

  1. /*
  2. ** $VER: IE_BatchProcess.ma 1.1 (14/10 Stockholm/Sweden)
  3. ** Copyright © 1996 by Patrik M Nydensten
  4. **
  5. ** Process all selected frames in MainActor's source project.
  6. ** Developed to work with MainActor 1.55 (Shareware/Aminet).
  7. ** May work with older/newer versions if arexx commands are the same.
  8. ** Uses IE Batch scripts. Requires Image Engineer 3.1 or higher.
  9. */
  10.  
  11. CFG_BATCH_DIR = '"IE:Arexx/Batch/"'
  12. CFG_START_DIR = '"IE:"'
  13. CFG_IE_PRIORITY = '-3'
  14.  
  15. options results
  16. signal on error
  17. signal on syntax
  18.  
  19. lf='0a'x ; dq='22'x ; sq='27'x
  20. old_ie_pri = '0'
  21.  
  22. if ~show('P','MAINACTOR') then exit
  23. address 'MAINACTOR'
  24.  
  25. 'PrintAndStoreTxt' " "
  26. 'PrintAndStoreTxt' " »> IE BatchProcess v1.0 by Patrik M Nydensten <«"
  27.  
  28. if ~show(ports,'IMAGEENGINEER') then do
  29.   'PrintTxt' "Unable to locate IE's arexx port!"
  30.   exit
  31. end
  32.  
  33. /* Get info from MainActor */
  34.  
  35. 'GetSPName'
  36. if RC ~= 0 then do
  37.   'PrintTxt' "No project loaded!"
  38.   exit
  39. end
  40.  
  41. 'GetSPSaver'
  42. parse var result ma_savertype ma_savername .
  43.  
  44. 'SetSPSaver' 'PIC' 'IFF'
  45.  
  46. 'GetSPInfo'
  47. parse var result width height colors pics caching loop cpf .
  48.  
  49. 'ScreenToFront'
  50.  
  51. 'RequestInteger' pics 'Enter total number of selected frames.'
  52. num_files = result
  53.  
  54. 'RequestSaveFile' "Select name for output dir."
  55. if RC ~= 0 then do
  56.   'PrintTxt' "Aborted ..."
  57.   exit
  58. end
  59. dst_path = strip(result,'B','"')
  60.  
  61. if pos(':',dst_path) = 0 then do
  62.   'PrintAndStoreTxt' "Bad directory path! You can not use a relative path."
  63.   'PrintTxt' "Please select a volume before entering output dir path and name."
  64.   exit
  65. end
  66. if exists(dst_path) then do
  67.   'PrintTxt' "Directory with that name already exists!"
  68.   exit
  69. end
  70.  
  71. address 'COMMAND' 'makedir' dst_path
  72.  
  73. /* Get batch script and check it  -------------------------------------- */
  74.  
  75. 'RequestFile' "Select IE Batch script."
  76. if RC ~= 0 then do
  77.   'PrintTxt' "Aborted ..."
  78.   exit
  79. end
  80. bscript = strip(result,'B','"')
  81.  
  82. if ~exists(bscript) then do
  83.   'PrintTxt' "Unable to find IE batch script!"
  84.   exit
  85. end
  86. else do
  87.   binfo = bei('INFO')  /* get extra info from batch */
  88.   if word(binfo,1) ~= 'OK' then do
  89.     'PrintTxt' "Error while accessing IE batch script!"
  90.     exit
  91.   end
  92. end
  93.  
  94. address 'IMAGEENGINEER'
  95. 'IE_TO_FRONT'
  96.  
  97. nil = info_add_setup(binfo)  /* setup optional extra info for batch */
  98.  
  99. /* Get config(s) from batch script  ------------------------------------ */
  100.  
  101. 'REQUEST' '"Select settings for first image."' '"Continue"'
  102. bopt_f = bei('CONFIG')
  103. 'REQUEST' '"Select new settings for last image?"' '"Yes, new|No, use same"'
  104. if (RESULT = 0) then bopt_l = bopt_f
  105. else do
  106.   'REQUEST' '"Select settings for last image."' '"Continue"'
  107.   bopt_l = bei('CONFIG' sq'"'bopt_f'"'sq)
  108.   'REQUEST' '"Select settings calculation mode."' '"Linear|Faster|Slower|Spline"'
  109.   calc_type = RESULT
  110.   if calc_type ~= 1 then nil = add_mathlib()
  111. end
  112.  
  113. if (bopt_f = '<ERROR>')|(bopt_l = '<ERROR>') then do
  114.   address 'MAINACTOR'
  115.   'PrintTxt' "Error while retrieving settings from batch script!"
  116.   exit
  117. end
  118.  
  119. 'REQUEST' '"Should I render the images?'lf||,
  120.   'Original sequence:' colors 'colors"' '"Yes, render|No, 24bit"'
  121. render_do = result
  122.  
  123. if render_do = 1 then do
  124.   'RENDER_GET' '"Select render options."' '0 135168 8 256 1 0'
  125.   render_opts = result
  126.  
  127.   if word(render_opts,5) = 0 then do
  128.     'GET_FILE' '"Select render palette to lock."' '"Lock"' '"IE:Palettes/"'
  129.     qpalette = result
  130.   end
  131.  
  132.   'REQUEST' '"Show rendering in foreground?"' '"Yes, show me|No, hide it"'
  133.   render_show = result
  134. end
  135.  
  136. /* Setup info & save out frames  --------------------------------------- */
  137.  
  138. 'PRIORITY_SET' CFG_IE_PRIORITY
  139. old_ie_pri = result
  140.  
  141. address 'MAINACTOR'
  142. 'ScreenToFront'
  143.  
  144. 'Save' dst_path||'/Image'
  145.  
  146. do i = 1 to 100000
  147.   if ~exists(dst_path||'/Image.'||right(i,5,'0')) then leave
  148. end
  149. if (num_files ~= i-1) then 'PrintAndStoreTxt' 'Warning: Number of saved images does not match user specified number.'
  150. num_files = (i - 1)
  151. if num_files < 1 then exit
  152.  
  153. 'PrintAndStoreTxt' "Image processing started ..." time()',' date()
  154.  
  155. /* Start processing  --------------------------------------------------- */
  156.  
  157. do i = 1 to num_files  /* Process loop */
  158.  
  159.   image_file = dst_path||'/Image.'||right(i,5,'0')
  160.  
  161.   'PrintTxt' "Processing image" i 'of' num_files'.'
  162.  
  163.   bei_proc = 'PROCESS' sq'"'image_file'"'sq sq'"'image_file'"'sq sq'"'calc_bopt(i)'"'sq get_info_add()
  164.   RESULT = bei(bei_proc)
  165.  
  166.   if RESULT = '<ERROR>' then do
  167.     'ScreenToFront'
  168.     'PrintAndStoreTxt' "Batch script returned error while processing image" i '!'
  169.     'PrintTxt' ' ('image_file') ... Exiting ...'
  170.     exit
  171.   end
  172.  
  173. end  /* end of process loop */
  174.  
  175. address 'MAINACTOR'
  176. 'ScreenToFront'
  177. 'PrintAndStoreTxt' "Image processing finished ..." time()',' date()
  178.  
  179. address 'IMAGEENGINEER'
  180. 'PRIORITY_SET' old_ie_pri
  181.  
  182. if render_do = 1 then do
  183.   address 'MAINACTOR' 'PrintAndStoreTxt' "Image rendering started ..." time()',' date()
  184.   do i = 1 to num_files  /* Process loop */
  185.   
  186.     image_file = dst_path||'/Image.'||right(i,5,'0')
  187.     
  188.     address 'MAINACTOR' 'ScreenToFront'
  189.     address 'MAINACTOR' 'PrintTxt' "Rendering image" i 'of' num_files'.'
  190.   
  191.     'OPEN' '"'image_file'"' '24'
  192.     project = result
  193.     
  194.     if word(render_opts,5) = 0 then 'PALETTE_LOAD' project '"'qpalette'"'
  195.     'RENDER_SET' project render_opts
  196.     if render_show then 'RENDER' project render_opts
  197.     else 'RENDER' project render_opts 'QUIET'
  198.  
  199.     'SAVE' project '"'image_file'"' '"ILBM CmpByteRun1"'
  200.     'CLOSE' project
  201.    
  202.   end  /* end of process loop */
  203.   address 'MAINACTOR' 'PrintAndStoreTxt' "Image rendering finished ..." time()',' date()
  204. end  /* do render */
  205.  
  206. /* Let MainActor act on created images */
  207.  
  208. address 'MAINACTOR'
  209.  
  210. if caching = "CACHING=YES" then    'OpenNewProject' "CACHING"
  211. else 'OpenNewProject'
  212.  
  213. 'SetSPLoader' 'PIC' 'Universal'
  214.  
  215. firstpic = dst_path || '/Image.00001'
  216. lastpic = dst_path || '/Image.' || right(num_files,5,'0')
  217.  
  218. LoadProject firstpic lastpic
  219.  
  220. SetSPSaver ma_savertype ma_savername
  221.  
  222. 'PrintAndStoreTxt' 'done ...'
  223.  
  224. exit
  225.  
  226. /* Procedures  ------------------------------------------------------*/
  227.  
  228. BEI:  /* Batch script caller */
  229.   parse arg bei_input
  230.  
  231.   interpret 'CALL' '"'bscript'"' bei_input
  232.   bei_output = RESULT
  233.  
  234.   address 'MAINACTOR'
  235. return bei_output
  236.  
  237. /* Config settings twiner  ---------------------------------------- */
  238.  
  239. Calc_bopt:
  240.   parse arg cur_filenum
  241.   calc_output = ''
  242.   bopt_fx = bopt_f ; bopt_lx = bopt_l
  243.   if (bopt_fx = bopt_lx) then calc_output = bopt_fx
  244.   else do forever
  245.     parse var bopt_fx val_fx bopt_fx
  246.     parse var bopt_lx val_lx bopt_lx
  247.     val_fx = strip(val_fx) ; val_lx = strip(val_lx)
  248.     if ((val_fx='')|(val_lx='')) then leave
  249.     if ((left(val_fx,1)='#')|(left(val_lx,1)='#')) then calc_output = calc_output val_fx
  250.     else do   /* do linear/spline calculation */
  251.       select
  252.         when calc_type = 1 then calc_output = calc_output trunc( (val_fx+(val_lx - val_fx)*(cur_filenum-1)/(num_files-1)) )
  253.         when calc_type = 2 then calc_output = calc_output trunc( val_fx+(val_lx-val_fx)*( (exp((-1)+5*(cur_filenum-1)/(num_files-1))-exp(-1)) /exp(4))/0.993262053 )
  254.         when calc_type = 3 then calc_output = calc_output trunc( val_fx+(val_lx-val_fx)*(1-( exp(4-5*(cur_filenum-1)/(num_files-1)) /exp(4)))*1.006783655 )         
  255.         when calc_type = 0 then calc_output = calc_output trunc( val_lx-(((cos(3.14159265*(cur_filenum-1)/(num_files-1))+1)/2)*(val_lx-val_fx)) )
  256.         otherwise nop
  257.       end /* select */
  258.     end  /* do calc */
  259.   end
  260. return strip(calc_output)
  261.  
  262. add_mathlib:
  263.   if ~show(L,'rexxmathlib.library') then do
  264.     if exists('LIBS:rexxmathlib.library') then do
  265.       if ~addlib('rexxmathlib.library',0,-30,0) then do
  266.         'PrintTxt' "Failed to load libs:rexxmathlib.library!"
  267.       end
  268.     end /* lib found on disk */
  269.     else do
  270.       'PrintTxt' "Failed to find libs:rexxmathlib.library!"
  271.     end
  272.   end /* lib exists in mem */
  273. return 'OK'
  274.  
  275. /* Output optional extra info if necessary  ---------------------------- */
  276.  
  277. get_info_add:
  278.   info_output = ''
  279.  
  280.   if pos('S',add_input)~=0 then do
  281.     if sec_force = 1 then info_output = sq'"'strip(sec_filelist,B,'"')'"'sq
  282.     else do
  283.       parse var sec_filelist file ';' sec_filelist
  284.       info_output = sq'"'strip(file,B,'"')'"'sq
  285.     end
  286.   end
  287.   if pos('A',add_input)~=0 then do
  288.     if alp_force = 1 then info_output = info_output sq'"'strip(alp_filelist,B,'"')'"'sq
  289.     else do
  290.       parse var alp_filelist file ';' alp_filelist
  291.       info_output = info_output sq'"'strip(file,B,'"')'"'sq
  292.     end
  293.   end
  294.   if pos('F',add_input)~=0 then do
  295.     info_output = info_output sq'"'i':'num_files'"'sq
  296.   end
  297.  
  298. return strip(info_output)
  299.  
  300. /* Retrieve Secondary/Alpha image(s)  --------------------------------- */
  301.  
  302. info_add_setup:
  303.   parse arg add_input
  304.  
  305.   if pos('S',add_input)~=0 then do
  306.     if substr(add_input,pos('S',add_input)+1,1) = '1' then sec_files = 1
  307.     else sec_files = num_files
  308.  
  309.     if sec_files > 1 then do  /* select multifile */
  310.       'REQUEST' '"This Batch script requires that you select'lf ||,
  311.                 num_files 'SECONDARY images."' '"Continue|Force single"'
  312.       if (RESULT = 0) then do
  313.         sec_files = 1 ; sec_force = 1
  314.       end
  315.     end
  316.     else do  /* select single file */
  317.       'REQUEST' '"This Batch script requires that you select'lf ||,
  318.                 'one SECONDARY image."' '" Continue "'
  319.     end
  320.  
  321.     if sec_files = 1 then 'GET_FILE' '"Select one SECONDARY image."' '" OK "' CFG_START_DIR
  322.     else 'GET_FILES' '"Select' num_files 'SECONDARY image(s)."' '" OK "' CFG_START_DIR
  323.     if (RC=5) then exit
  324.     sec_filelist = RESULT
  325.     if sec_filelist = '' then exit
  326.  
  327.     parse var sec_filelist file_1 ';' file_2 ';' nil
  328.     if (file_2~='')&(nil='')&(sec_files~=1) then do  /* Ask for index range selection */
  329.       result = check_index_range(file_1,file_2)
  330.       parse var result  '"'sec_filelist'"' '"'sec_files'"'
  331.     end  /* Really index files? */
  332.  
  333.   end  /* end of get SEC */
  334.  
  335.   if pos('A',add_input)~=0 then do
  336.     if substr(add_input,pos('A',add_input)+1,1) = '1' then alp_files = 1
  337.     else alp_files = num_files
  338.  
  339.     if alp_files > 1 then do  /* select multifile */
  340.       'REQUEST' '"This Batch script requires that you select'lf ||,
  341.                 num_files 'ALPHA images."' '"Continue|Force single"'
  342.       if (RESULT = 0) then do
  343.         alp_files = 1 ; alp_force = 1
  344.       end
  345.     end
  346.     else do  /* select single file */
  347.       'REQUEST' '"This Batch script requires that you select'lf ||,
  348.                 'one ALPHA image."' '" Continue "'
  349.     end
  350.  
  351.     if alp_files = 1 then 'GET_FILE' '"Select one ALPHA image."' '" OK "' CFG_START_DIR
  352.     else 'GET_FILES' '"Select' num_files 'ALPHA image(s)."' '" OK "' CFG_START_DIR
  353.     if (RC=5) then exit
  354.     alp_filelist = RESULT
  355.     if alp_filelist = '' then exit
  356.  
  357.     parse var alp_filelist file_1 ';' file_2 ';' nil
  358.     if (file_2~='')&(nil='')&(alp_files~=1) then do  /* Ask for index range selection */
  359.       result = check_index_range(file_1,file_2)
  360.       parse var result '"'alp_filelist'"' '"'alp_files'"'
  361.     end  /* Really index files? */
  362.  
  363.   end  /* end of get ALP */
  364.  
  365. return 'OK'
  366.  
  367. Check_index_range:
  368.   parse arg file_1, file_2
  369.   range_list = file_1';'file_2
  370.   num_range = 2
  371.   
  372.   basename = substr(file_1,1,lastpos('.',file_1))
  373.   basename_2 = substr(file_2,1,lastpos('.',file_2))
  374.   index_1 = substr(file_1,lastpos('.',file_1)+1) ; zlen = length(index_1)
  375.   index_2 = substr(file_2,lastpos('.',file_2)+1)
  376.   if (basename=basename_2)&(datatype(index_1,'N'))&(datatype(index_2,'N')) then do
  377.     'REQUEST' '"You have selected two images, both with the same basename'lf||,
  378.             'and both with an index number. Would you like to include all'lf||,
  379.             'images within the index range? ('index_2-index_1+1' images)"' '"Yes, index range|No, two images"'
  380.     if (Result = 1) then do
  381.       range_list = '' ; index_fix = 0
  382.       do i = strip(index_1,L,'0') to strip(index_2,L,'0')
  383.         if ~exists(basename || right(i,zlen,'0')) then do
  384.           if skip_all ~= 1 then do
  385.             'REQUEST' '"Could not locate file:'lf ||basename||right(i,zlen,'0')'"' '"Skip image|Skip all|Abort action"'
  386.             if Result ~= 0 then index_fix = index_fix + 1
  387.             if Result = 2 then skip_all = 1
  388.             if Result = 0 then exit
  389.           end
  390.           else index_fix = index_fix + 1
  391.         end
  392.         else range_list = range_list || basename || right(i,zlen,'0')||';'
  393.       end
  394.       num_range = index_2 - index_1 + 1 - index_fix
  395.       if (index_fix>0) then 'REQUEST' '"Skipped' index_fix 'images.' num_range 'images found."' '"Continue"'
  396.       if num_range < 2 then exit
  397.     end  /* Do index range? */
  398.   end  /* Is really index files? */
  399.  
  400. return '"'range_list'"' '"'num_range'"'
  401.  
  402. /*******************************************************************/
  403. /* This is where control goes when an error code is returned by IE */
  404. /* It puts up a message saying what happened and on which line     */
  405. /*******************************************************************/
  406. syntax:
  407.   address 'IMAGEENGINEER'
  408.   'PRIORITY_SET' old_ie_pri
  409.     LAST_ERROR
  410.     IE_ERR = result
  411.   address 'MAINACTOR'
  412.   'ScreenToFront'
  413.   'PrintTxt' 'Error: Script failed ('RC') on line' SIGL '!'
  414.   if IE_ERR ~=RESULT then 'IE error message:' IE_ERR
  415.   exit
  416. end
  417.  
  418. error:
  419.   address 'IMAGEENGINEER'
  420.   'PRIORITY_SET' old_ie_pri
  421.     LAST_ERROR
  422.     IE_ERR = result
  423.   address 'MAINACTOR'
  424.   'ScreenToFront'
  425.   'PrintTxt' 'Error: Script failed on line' SIGL
  426.   if IE_ERR ~=RESULT then 'IE error message:' IE_ERR
  427.   exit
  428. end
  429.  
  430.